<%@ page language="java" pageEncoding="utf-8" %>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%
    String path = request.getContextPath();
    String basePath = request.getScheme() + "://"
            + request.getServerName() + ":" + request.getServerPort()
            + path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html>
<head>
    <base href="<%=basePath%>">

    <title>${sessionScope.topicName} - 全部数据</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf8"/>

    <%@include file="im.jsp" %>
    <link rel="stylesheet" href="css/pagination.css"/>
    <link rel="stylesheet" href="css/subPage.css"/>
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/jquery.pagination.js"></script>

    <link href="js/jquery-ui-1.8.13/themes/base/jquery-ui.css" rel="stylesheet" type="text/css"/>
    <script src="js/jquery-ui-1.8.13/ui/jquery-ui.js"></script>

    <script type="text/javascript">
        $(function () {
            language = "${language}";	//全局变量
            var count = "${count}";
            startDate = "${startDate}";
            endDate = "${endDate}";
            type = "${type}";
            if (startDate != null && startDate != "null") {
                $("#startDate").val(startDate);
            }
            if (endDate != null && endDate != "null") {
                $("#endDate").val(endDate);
            }
            topicId = "${topicId}";
            if (language == null) {
                language = "all";
            }
            page = 10; //!!!!!!每页个数！！！！！！
            //initContent(1);
            var initPagination = function () {
                // 创建分页
                $("#Pagination").pagination(count, {
                    num_edge_entries: 1, //边缘页数
                    num_display_entries: 6, //主体页数
                    callback: pageselectCallback,
                    items_per_page: page, //每页显示1项
                    prev_text: "前一页",
                    next_text: "后一页"
                });
            }();

            function pageselectCallback(page_index, jq) {
                initContent(page_index);
                return false;
            }

            function initContent(page_index) {
                $.ajax({
                    type: "GET",
                    url: "newslistAction.do?method=all",//实际得到的是xxxxAction  转向的页面 xxx.jsp中输出的内容，
                    data: {
                        "pagesize": page,
                        "start": page_index + 1,
                        "language": language,
                        "sd": startDate,
                        "ed": endDate,
                        "type": type
                    },
                    success: function (msg) {

                        var obj = eval('(' + msg + ')');
                        var count = obj.count;

                        $("input[name=count]").val(count);
                        // 创建分页
                        page = 10; //!!!!!!每页个数！！！！！！

                        $("input[name=count]").val(count);
                        $("div.title").html(obj.tag);
                        $("#Searchresult").empty();
                        var list = obj.result;
                        for (var i = 0; i < list.length; i++) {
                            var pa = list[i];
                            $("#Searchresult")
                                    .append("<div class=\"result\">" + "<h4><a target=\"_blank\" href=\""
                                            + pa.link + "\">"
                                            + pa.title + "</a>" + "</h4>" + "["
                                            + pa.site + "]["
                                            + pa.time + "]" + "<p>"
                                            + (pa.abstext == null ? "" : pa.abstext) + "</p></div>");
                        }

                    }
                });
            }

        });
    </script>

</head>

<body>
<logic:equal name="user" value="administrator">
<div id="content" class="container">
        <%@include file="top.jsp" %>

    <div class="row">
        <%@include file="left.jsp" %>

        <input type="hidden" name="count" value="200"/>

        <div class="col-md-10">

            <div id="right_left">
                <div>
                    起始日期：<input id="startDate" name="sd"/>
                    结束日期：<input id="endDate" name="sd"/>
                    <input type="button" name="datenewsbt" value="确定"/>
                </div>
                <script type="text/javascript">
                    $("#startDate").datepicker({
                        dateFormat: "yy-mm-dd",	//格式
                        changeYear: true,	//可以改变年份
                        firstDay: 1,	//周始日
                        dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
                        monthNamesShort: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
                        changeMonth: true	//可以改变月份
                    });
                    $("#endDate").datepicker({
                        dateFormat: 'yy-mm-dd',//格式
                        changeYear: true,	//可以改变年份
                        firstDay: 1,	//周始日
                        dayNamesMin: ['日', '一', '二', '三', '四', '五', '六'],
                        monthNamesShort: ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10', '11', '12'],
                        changeMonth: true	//可以改变月份
                    });
                    $("input[name=datenewsbt]").click(function () {
                        var sd = $("#startDate").val();
                        var ed = $("#endDate").val();
                        var type = $("input:radio[name=type]:checked").val();
                        if (sd > ed && !(sd == '' || ed == '')) {
                            alert("请重新选择");
                        } else {
                            window.location.href = "newsallAction.do?method=count&language=" + language + "&sd=" + sd + "&ed=" + ed + "&type=" + type;
                        }
                    });
                </script>
                <input type="radio" name="type" value="news"/>新闻&nbsp;
                <input type="radio" name="type" value="bbs"/>论坛&nbsp;
                <input type="radio" name="type" value="weibo"/>微博&nbsp;
                <input type="radio" name="type" value="blog"/>博客&nbsp;
                <script type="text/javascript">
                    $("input[name=type][value=${type}]").attr("checked", true);
                </script>
                <div class="titlebox" style="border-bottom: 1px solid darkgray; padding:0 3px;">
                    <div class="title"></div>
                </div>

                <div id="Searchresult">分页初始化完成后这里的内容会被替换。</div>
                <div id="Pagination" class="pagination">
                    <!-- 这里显示分页 -->
                </div>

            </div>
            <!--end of right-->
        </div>
    </div>
        <%@ include file="foot.jsp" %>
    </logic:equal>
    <logic:empty name="user">
    Access Rejected! Error 404
    </logic:empty>
</body>
</html>
